using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Events;

public class DetectionZone : MonoBehaviour
{
    public Collider2D detectedObjs;
    public float viewRadius;
    public LayerMask playerLayerMask;
    public UnityEvent onPlayerEnter;
    public UnityEvent onPlayerExit;

    void Update()
    {
        bool previousState = detectedObjs != null;
        Collider2D collider = Physics2D.OverlapCircle(transform.position, viewRadius, playerLayerMask);
        detectedObjs = collider;

        if (collider != null)
        {
            detectedObjs = collider;
        }
        if (previousState && detectedObjs == null)
            onPlayerExit?.Invoke();
    }
    private void OnDrawGizmos()
    {
        Gizmos.DrawWireSphere(transform.position, viewRadius);
    }
}
